layui.use(['layer','upload'],function (){
   let layer = layui.layer,upload =layui.upload;

   layui.upload.render({
       elem:'#uploadPhoto',
       url:'/userinfo/updateUserInfo/uploadPhoto',
       done:function (res,index,upload){
           if (valueIsEqual(res.code,'00')){
               $(".img-upPhoto").attr("src",res.data);
               $("input[name=photoNm]").val(res.data);
           }
       },
       error:function (){
           //上传失败之后的回调
       }
   });
});

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/24
* @description: 回显用户头像
*/
$(function (){
    sendAjax("/userinfo/updateUserInfo/showPhoto",null,function (res) {
        if (valueIsEqual(res.code,"00")){
            $(".img-old").attr("src",res.data);
        }else {
            $(".img-old").attr("src","/images/defalut_upload_photo.png");
        }
    });
})

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/24
* @description: 修改头像
*/
function updatePhoto() {
    let photoPath = $("input[name=photoNm]").val();
    if (valueIsEmpty(photoPath)){
        top.layui.layer.msg('请先上传头像',{icon:0,time:1500});
        return;
    }
    let photoJson = {
        "urPhotoPath" : photoPath
    };
    sendAjax("/userinfo/updateUserInfo/checkPhoto",photoJson,function (res) {
        if (valueIsEqual(res.code,'00')){
            //获取当前弹窗的索引，并关闭；parent 是 layui 定义的全局变量
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }else {
            top.layui.layer.msg(res.data,{icon:0,time:1500});
        }
    });
}

